/* Copyright Paul Reiche, Fred Ford. 1992-2002, Christopher Night 2013

This file is part of the HTML5 port of Ur-Quan Masters (UQM-HTML5)

UQM-HTML5 is free software: you can redistribute it and/or modify it under the terms of the GNU
General Public License as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

UQM-HTML5 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
Public License for more details.

You should have received a copy of the GNU General Public License along with this program.  If not,
see <http://www.gnu.org/licenses/>. */


// Extremely simplified port of src/uqm/galaxy.c

var galaxy = {
	// Start with the most background stars, so we can just draw them in order
	starcounts: [90, 60, 30],
	starfactors: [4, 2, 1],
	
	init: function () {
		var sframes = graphics.getfarray("lbm/stars.ani")
		this.starcolors = [
			"white",
			sframes[0],
			sframes[1],
		]
		this.starps = []
		for (var k = 0 ; k < this.starcounts.length ; ++k) {
			this.starps.push([])
			for (var j = 0 ; j < this.starcounts[k]; ++j) {
				this.starps[k].push([Math.random() * 100000, Math.random() * 100000])
			}
		}
	},
	draw: function () {
		for (var k = 0 ; k < this.starps.length ; ++k) {
			var color = this.starcolors[k], ps = this.starps[k], f = this.starfactors[k]
			ps.forEach(function (p) {
				var sp = process.startoscreen(p[0], p[1], f)
				var x = sp[0], y = sp[1]
				if (color.img) context.space.drawframe(color, x, y)
				else context.space.drawpoint(color, x, y)
			})
		}
	},
}

